<?php

namespace App\Http\Controllers;
use App\Http\Controllers\BaseController;
use App\Post;
use App\Models\Article;
use DB;

class PostController extends BaseController
{
    public function index()
    {


       // DB::beginTransaction();
       

  /*
        $article = new Post();
        $article->name="pangxianfei";

        $article->save();

        foreach (config('translatable.locales') as $locale=>$item) {
            $article->translateOrNew($locale)->title = "Title-3 {$item}";
            $article->translateOrNew($locale)->content = "Text-3 {$item}";
        }

        $article->save();

        return 'ok';
 */

        //return Post::translatedIn('en')->get();

        // $post = Post::first();
         //echo $post->translate('en')->title; // My first post
		 
		 
		 
        $id=8;
        $posts = Post::whereTranslation('id', $id)->first();
		return $posts->translateOrNew('zh');;
		
		
		
		
		
		
		
		
		
		
		
		if(empty($posts->hasTranslation('tu'))){
 
			$posts->translateOrNew('tu')->title = "tu title";
			$posts->translateOrNew('tu')->content = "tu content";
			$posts->save();
		}

        //return $this->view(compact('theme::blog')->with('posts', $posts);
        //return $this->view(compact('posts'));
    }

    public function show($id)
    {
        $article =  Article::where('id',17)->first();


        echo $article->translate('jp')->description; 
        
       // $post = Post::whereTranslation('post_id', $id)->firstOrFail();
         /*
        if ($post->translate()->where('id', $id)->first()->locale != app()->getLocale()) {

            return redirect()->route('post.show', $post->translate()->id);
        }
        */


       // return view('theme::post')->with('post', $post);
    }
}
